package com.forever.thread;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.ThreadFactory;

public class ThreadFactoryImpl implements ThreadFactory {

	@SuppressWarnings("static-access")
	@Override
	public Thread newThread(Runnable r) {
		ThreadGroup group = new ThreadGroup("my_group");
		Thread t = new Thread(group, r, "my_thread");
		t.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread t, Throwable e) {
				System.out.println("id:" + t.getId() + ", cause:" + e.getMessage());
			}
		});
		return t;
	}

}
